home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / inkey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  2.4 KB  |  137 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include "conio.h"
  6. #include "bios.h"
  7. #include "edt.h"
  8. #define true (!false)
  9. #define false 0
  10. int fner(char *s);
  11. int scr_refresh(void);
  12. int scr_getch(void);
  13. char *function_bar()
  14. {
  15.     return "F1-Help  F2-Save  F3-Load  F4-Saveas  F5-Errs  F9-Graph  F10-Drawit ^Z Quit";
  16. }
  17.  
  18.  
  19. struct keymatch {int m; int val;};
  20. /* commands using hi 8 bits of bios, e.g. arrow keys */
  21. struct keymatch kmatch1[] = {
  22.     0x0e, edelete,
  23.     0x4d, eright,
  24.     0x4b, eleft,
  25.     0x48, eup,
  26.     0x53, edelright,
  27.     0x50, edown,
  28.     0x4a, edelline,
  29.     0x3b, ehelp,
  30.     0x3c, esave,
  31.     0x3d, eload,
  32.     0x3e, esaveas,
  33.     0x3f, eshowerror,
  34.     0x43, egraphmenu,
  35.     0x44, edrawit,
  36.     0x49, epageup,
  37.     0x51, epagedown,
  38.     0x47, ebol,
  39.     0x4f, eeol,
  40.     0,0
  41. };
  42. /* Normal key and ^ commands  commands */
  43. struct keymatch kmatch2[] = {
  44.     13, ereturn,
  45.     3, equit,
  46.     4, eword,
  47.     5, eshowerror,
  48.     8, ehelp,
  49.     19, eshell,
  50.     20, etrace,
  51.     12, efindnext,
  52.     21, eundelline,
  53.     25, edelline,
  54.     26, eescape,
  55.     27, eescape,
  56.     0,0
  57. };
  58. /* Control K commands */
  59. struct keymatch kmatch3[] = {
  60.     'b', eselect,
  61.     'v', emove,
  62.     'k', emark,
  63.     'c', ecopy,
  64.     'y', ecut,
  65.     'u', epaste,
  66.     'p', epaste,
  67.     'r', eblockread,
  68.     'w', eblockwrite,
  69.     'm', egraphmenu,
  70.     'l', eload,
  71.     'd', edrawit,
  72.     's', esave,
  73.     'x', equit,
  74.     0,0
  75. };
  76. /* Control Q commands */
  77. struct keymatch kmatch4[] = {
  78.     'f', esearch,
  79.     'c', eendoffile,
  80.     'r', etopoffile,
  81.     0,0
  82. };
  83.  
  84. text_inkey()
  85. {
  86.     int cc,i,c1,c2,ff;
  87.     scr_refresh();
  88. loop1:    cc = bioskey(0);
  89.     ff = bioskey(2);
  90.     c1 = (cc & 0xff00)>>8;
  91.     c2 = (cc & 0xff);
  92.     if (c1==45 && ((ff & 8)>0) ) return eexitnow;
  93.     for (i=0;kmatch1[i].m!=0;i++)
  94.         if (kmatch1[i].m==c1) return kmatch1[i].val;
  95.  
  96.     switch(c2) {
  97.       default:
  98.         for (i=0;kmatch2[i].m!=0;i++)
  99.         if (kmatch2[i].m==c2) return kmatch2[i].val;
  100.         break;
  101.       case 17:
  102.         fner("^Q  F=Find string,  R=Top of file,  C=End of file");
  103.         cc = bioskey(0);
  104.         c2 = (cc & 0xff);
  105.         if (c2<32) c2 = c2 + 'a' - 1;
  106.         c2 = tolower(c2);
  107.         for (i=0;kmatch4[i].m!=0;i++)
  108.         if (kmatch4[i].m==c2) return kmatch4[i].val;
  109.         fner("Unrecognized Quick movement command");
  110.         goto loop1;
  111.       case 11:
  112.         fner("^K  B=begin block,  P=Paste,  Y=Cut,  K=End block");
  113.         cc = bioskey(0);
  114.         c2 = (cc & 0xff);
  115.         if (c2<32) c2 = c2 + 'a' - 1;
  116.         c2 = tolower(c2);
  117.         for (i=0;kmatch3[i].m!=0;i++)
  118.         if (kmatch3[i].m==c2) return kmatch3[i].val;
  119.         fner("Unrecognized block command");
  120.         goto loop1;
  121.     }
  122.     return c2;
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.